<?php

class Systype {
    static public function getSystype($string) {
        if (self::matchURL($string)) {
            if (self::matchVideo($string)) {
                return VIDEO;
            }
            return URL;
        }
        if ($string) {
            return NODE;
        }
        return false;
    }
    
    static private function matchURL($string) {
        return (bool)preg_match('#^http://(www.)?[\w]+\.[\w]+#',$string);
    }
    
    static private function matchVideo($string) {
        return (bool)preg_match('#^http://www.youtube.com/watch\?v=([\w]{11})#',$string);
    }
    
    static public function isResource($systype) {
        return ($systype != NODE);
    }

	static public function getCleanUrl($url) {
		$matches = array();
		if (preg_match('#^http://www.youtube.com/watch\?v=([\w]{11})#',$string,$matches)) {
			return 'http://www.youtube.com/watch?v='.array_pop($matches);
		}
		if (preg_match('#^http://(www.)?[\w]+\.[\w]+#',$string,$matches)) {
			return $matches[0];
		}
		return '';
	}
}
